let test = true;
var util=require('util.js')
var testSubmitOrder = function(data,callback) {
    
        //callback(true, ret);
        wx.navigateTo({
          url: '../testpay/testpay?out_trade_no=' + data.outTradeNo+"&orderNo="+data.orderNo,
        })  
  }
  var payOrder = function(id,callback) {
    var that = this;
    var url = util.url.order_pay;
    url += "?id=" + id;
    util.fetchGet(
      url,
      function(data) {
        if (test) {
          testSubmitOrder(data.data,callback);
        } else {
          submitOrder(data.data,callback);
        }

      }
    )
  }

var submitOrder = function(data,callback) {
  wx.requestPayment({
    'timeStamp': data.timeStamp,
    'nonceStr': data.nonceStr,
    'package': 'prepay_id=' + data.prepatId,
    'signType': data.signType,
    'paySign': data.paySign,
    'success': function(res) {
      console.log(res);
      callback(true, res)
    },
    'fail': function(res) {
      console.log(res);
      callback(false,res);
    }
  })

}
var createPay=function(data,callback){
  if (test) {
    testSubmitOrder(data, callback);
  } else {
    submitOrder(data, callback);
  }
}
module.exports={
  payOrder: payOrder,
  createPay: createPay
}